﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace YArchitech.Plumbing
{
	internal class WaterAndAirCal
	{
		public static double GetDensityByTemperature(double dTemperature)
		{
			double result = 1000.0;
			if (WaterAndAirCal._WaterDensityItem == null)
			{
				return result;
			}
			int num = WaterAndAirCal._WaterDensityItem.Keys.Min();
			int num2 = WaterAndAirCal._WaterDensityItem.Keys.Max();
			if (dTemperature < (double)num)
			{
				result = WaterAndAirCal._WaterDensityItem[num];
			}
			else if (dTemperature > (double)num2)
			{
				result = WaterAndAirCal._WaterDensityItem[num2];
			}
			else
			{
				result = WaterAndAirCal._WaterDensityItem[(int)dTemperature];
			}
			return result;
		}

		public static double GetPs(double dTemperature)
		{
			if (dTemperature < -100.0 || dTemperature > 200.0)
			{
				return -1.0;
			}
			double num = dTemperature + WaterAndAirCal.C_dT273;
			double num2 = -5674.5359;
			double num3 = 6.3925247;
			double num4 = -0.009677843;
			double num5 = 6.2215701E-07;
			double num6 = 2.0747825E-19;
			double num7 = -9.484024E-13;
			double num8 = 4.1635019;
			double num9 = -5800.2206;
			double num10 = 1.3914993;
			double num11 = -0.04860239;
			double num12 = 4.1764768E-05;
			double num13 = -1.4452093E-08;
			double num14 = 6.5459673;
			double result;
			if (num < WaterAndAirCal.C_dT273)
			{
				result = Math.Exp(num2 / num + num3 + num4 * num + num5 * Math.Pow(num, 2.0) + num6 * Math.Pow(num, 3.0) + num7 * Math.Pow(num, 4.0) + num8 * Math.Log10(num));
			}
			else
			{
				result = Math.Exp(num9 / num + num10 + num11 * num + num12 * Math.Pow(num, 2.0) + num13 * Math.Pow(num, 3.0) + num14 * Math.Log10(num));
			}
			return result;
		}

		public static double C_dg = 9.80665;

		public static double C_dT273 = 273.15;

		public static double C_dPa_std = 101325.0;

		public static double C_dPs_20 = 2364.9;

		public static double C_dHs_20 = 0.2411;

		public static double C_dHa_std = 10.332274527998859;

		private static Dictionary<int, double> _WaterDensityItem = new Dictionary<int, double>
		{
			{
				0,
				999.9
			},
			{
				1,
				999.9
			},
			{
				2,
				1000.0
			},
			{
				3,
				1000.0
			},
			{
				4,
				1000.0
			},
			{
				5,
				1000.0
			},
			{
				6,
				1000.0
			},
			{
				7,
				999.95
			},
			{
				8,
				999.9
			},
			{
				9,
				999.8
			},
			{
				10,
				999.7
			},
			{
				11,
				999.58
			},
			{
				12,
				999.46
			},
			{
				13,
				999.34
			},
			{
				14,
				999.22
			},
			{
				15,
				999.1
			},
			{
				16,
				998.92
			},
			{
				17,
				998.74
			},
			{
				18,
				998.56
			},
			{
				19,
				998.38
			},
			{
				20,
				998.2
			},
			{
				21,
				997.98
			},
			{
				22,
				997.76
			},
			{
				23,
				997.54
			},
			{
				24,
				997.32
			},
			{
				25,
				997.1
			},
			{
				26,
				996.82
			},
			{
				27,
				996.54
			},
			{
				28,
				996.26
			},
			{
				29,
				995.98
			},
			{
				30,
				995.7
			},
			{
				31,
				995.38
			},
			{
				32,
				995.06
			},
			{
				33,
				994.74
			},
			{
				34,
				994.42
			},
			{
				35,
				994.1
			},
			{
				36,
				993.73
			},
			{
				37,
				993.36
			},
			{
				38,
				992.98
			},
			{
				39,
				992.61
			},
			{
				40,
				992.24
			},
			{
				41,
				991.84
			},
			{
				42,
				991.44
			},
			{
				43,
				991.05
			},
			{
				44,
				990.65
			},
			{
				45,
				990.25
			},
			{
				46,
				989.81
			},
			{
				47,
				989.38
			},
			{
				48,
				988.94
			},
			{
				49,
				988.51
			},
			{
				50,
				988.07
			},
			{
				51,
				987.6
			},
			{
				52,
				987.13
			},
			{
				53,
				986.67
			},
			{
				54,
				986.2
			},
			{
				55,
				985.73
			},
			{
				56,
				985.24
			},
			{
				57,
				984.75
			},
			{
				58,
				984.26
			},
			{
				59,
				983.77
			},
			{
				60,
				983.28
			},
			{
				61,
				982.75
			},
			{
				62,
				982.22
			},
			{
				63,
				981.69
			},
			{
				64,
				981.16
			},
			{
				65,
				980.63
			},
			{
				66,
				980.08
			},
			{
				67,
				979.54
			},
			{
				68,
				978.99
			},
			{
				69,
				978.45
			},
			{
				70,
				977.9
			},
			{
				71,
				977.29
			},
			{
				72,
				976.68
			},
			{
				73,
				976.07
			},
			{
				74,
				975.46
			},
			{
				75,
				974.85
			},
			{
				76,
				974.25
			},
			{
				77,
				973.65
			},
			{
				78,
				973.04
			},
			{
				79,
				972.44
			},
			{
				80,
				971.84
			},
			{
				81,
				971.19
			},
			{
				82,
				970.53
			},
			{
				83,
				969.88
			},
			{
				84,
				969.22
			},
			{
				85,
				968.57
			},
			{
				86,
				967.92
			},
			{
				87,
				967.28
			},
			{
				88,
				966.63
			},
			{
				89,
				965.99
			},
			{
				90,
				965.34
			},
			{
				91,
				964.64
			},
			{
				92,
				963.93
			},
			{
				93,
				963.23
			},
			{
				94,
				962.52
			},
			{
				95,
				961.82
			},
			{
				96,
				961.13
			},
			{
				97,
				960.45
			},
			{
				98,
				959.77
			},
			{
				99,
				959.08
			},
			{
				100,
				958.4
			}
		};
	}
}
